<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<script>
description('Check stepping-up and -down for date input fields from renderer.');
if (!window.eventSender)
    debug('This test requires eventSender.');

var input = document.createElement('input');
input.type = 'date';
document.body.appendChild(input);

function setInputAttributes(value, min, max) {
    input.value = value;
    input.min = min;
    input.max = max;
}

function stepUp(value, min, max) {
    setInputAttributes(value, min, max);
    eventSender.keyDown('ArrowUp');
    return input.value;
}

function stepDown(value, min, max) {
    setInputAttributes(value, min, max);
    eventSender.keyDown('ArrowDown');
    return input.value;
}

input.focus();
debug('Function arguments are (value, min, max, [keySequence]).');
debug('Month');
shouldBeEqualToString('stepUp("2000-05-01", "2000-05-01", "2000-10-31")', '2000-06-01');
shouldBeEqualToString('stepDown("2000-05-01", "2000-05-01", "2000-10-31")', '2000-10-01');
shouldBeEqualToString('stepUp("2000-05-01", "2000-02-01", "2000-05-31")', '2000-02-01');
shouldBeEqualToString('stepDown("2000-05-01", "2000-02-01", "2000-05-31")', '2000-04-01');
shouldBeEqualToString('stepUp("2000-05-01", "2000-08-01", "2000-10-31")', '2000-08-01');
shouldBeEqualToString('stepDown("2000-05-01", "2000-08-01", "2000-10-31")', '2000-10-01');
shouldBeEqualToString('stepUp("2000-05-01", "2000-03-01", "2000-03-31")', '2000-03-01');
shouldBeEqualToString('stepDown("2000-05-01", "2000-03-01", "2000-03-31")', '2000-03-01');
shouldBeEqualToString('stepUp("2000-05-01", "2000-03-01", "2001-05-31")', '2000-06-01');
shouldBeEqualToString('stepDown("2000-05-01", "2000-05-01", "2001-08-31")', '2000-04-01');

debug('Day');
eventSender.keyDown('ArrowRight');
shouldBeEqualToString('stepUp("2000-05-10", "2000-05-10", "2000-05-20")', '2000-05-11');
shouldBeEqualToString('stepDown("2000-05-10", "2000-05-10", "2000-05-20")', '2000-05-20');
shouldBeEqualToString('stepUp("2000-05-10", "2000-05-05", "2000-05-10")', '2000-05-05');
shouldBeEqualToString('stepDown("2000-05-10", "2000-05-05", "2000-05-10")', '2000-05-09');
shouldBeEqualToString('stepUp("2000-05-10", "2000-05-20", "2000-05-30")', '2000-05-20');
shouldBeEqualToString('stepDown("2000-05-10", "2000-05-20", "2000-05-30")', '2000-05-30');
shouldBeEqualToString('stepUp("2000-05-10", "2000-05-05", "2000-05-05")', '2000-05-05');
shouldBeEqualToString('stepDown("2000-05-10", "2000-05-05", "2000-05-05")', '2000-05-05');
shouldBeEqualToString('stepUp("2000-05-10", "2000-05-05", "2001-05-10")', '2000-05-11');
shouldBeEqualToString('stepDown("2000-05-10", "2000-05-10", "2001-05-15")', '2000-05-09');
shouldBeEqualToString('stepUp("2000-05-10", "2000-05-05", "2000-06-10")', '2000-05-11');
shouldBeEqualToString('stepDown("2000-05-10", "2000-05-10", "2000-06-15")', '2000-05-09');

debug('Year');
setInputAttributes(null, null, null, null);
eventSender.keyDown('ArrowRight');
shouldBeEqualToString('stepUp("2000-01-01", "2000-01-01", "2009-12-31")', '2001-01-01');
shouldBeEqualToString('stepDown("2000-01-01", "2000-01-01", "2009-12-31")', '2009-01-01');
shouldBeEqualToString('stepUp("2000-01-01", "1990-01-01", "2000-12-31")', '1990-01-01');
shouldBeEqualToString('stepDown("2000-01-01", "1990-01-01", "2000-12-31")', '1999-01-01');
shouldBeEqualToString('stepUp("275760-01-01", "1990-01-01", null)', '1990-01-01');
shouldBeEqualToString('stepDown("1990-01-01", "1990-01-01", null)', '275760-01-01');
shouldBeEqualToString('stepUp("2000-01-01", null, "2000-12-31")', '0001-01-01');
shouldBeEqualToString('stepDown("0001-01-01", null, "2000-12-31")', '2000-01-01');
shouldBeEqualToString('stepUp("1990-01-01", "2000-01-01", "2009-12-31")', '2000-01-01');
shouldBeEqualToString('stepDown("1990-01-01", "2000-01-01", "2009-12-31")', '2009-01-01');
shouldBeEqualToString('stepUp("2020-01-01", "2000-01-01", "2000-12-31")', '2000-01-01');
shouldBeEqualToString('stepDown("2020-01-01", "2000-01-01", "2000-12-31")', '2000-01-01');

debug('');
input.remove();
</script>
</body>
</html>
